﻿using Domain.Entity;
using Domain.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
	public class CFSKRepository : ICFSKRepository
	{
		private readonly MyDbContext myDbContext;

		public CFSKRepository(MyDbContext myDbContext)
		{
			this.myDbContext = myDbContext;
		}
		public async Task<bool> AddCFSKAsync(CFSK cFSK)
		{
			myDbContext.CFSK.Add(cFSK);
			return await myDbContext.SaveChangesAsync() > 0;
		}

		public async Task<bool> DeleteCFSKAsync(int id)
		{
			CFSK cFSK = new CFSK
			{
				FskId = id
			};
			myDbContext.CFSK.Remove(cFSK);
			return await myDbContext.SaveChangesAsync() > 0;
		}

		public async Task<List<CFSK>> GetCFSKAsync()
		{
			return await myDbContext.CFSK.ToListAsync();
		}

		public async Task<List<CFSK>> GetCFSKAsyncById(string kid)
		{
			return await myDbContext.CFSK.Where(e=>e.FirstKindId==kid).ToListAsync();
		}

		public async Task<bool> UpdateCFSKAsync(CFSK cFSK)
		{
			myDbContext.CFSK.Update(cFSK);
			return await myDbContext.SaveChangesAsync() > 0;
		}
	}
}
